<template>
  <div class="header-box">
    <div class="header-left">
      <!-- <img class="header-logo" src="@/assets/images/logo.svg" alt="logo" style="cursor: pointer" @click="goHome" /> -->
      <div class="header-title" :style="{ color: zColor}">边缘计算网关管理端</div>
      <div class="header-menu"></div>
    </div>
    <div class="header-right">
      <!-- <img class="header-avatar " src="../assets/images/skinpeeler.png" @click="getAddcolor" /> -->


      <img class="header-avatar" :src="user.imgUrl ? user.imgUrl : defaultAvatar" alt="头像" style="cursor: pointer" />
      
      <el-dropdown placement="top-start">
        <div :style="{ color: zColor}"  class="header-user-name" >{{ user.name }}</div>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="loginOut">退出登陆</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
    </div>
  </div>
</template>

<script setup>
import defaultAvatar from '@/assets/images/default-avatar.png'
import { reactive, getCurrentInstance ,ref} from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const zColor=ref('rgba(255, 255, 255, 0.9)')
const headColor = getComputedStyle(document.documentElement).getPropertyValue('--header-font-color');//获取全局首页颜色
const { proxy } = getCurrentInstance()
const user = reactive({
  name: 'admin',
  imgUrl: ''
})
const loginOut = () => {
  ElMessageBox.confirm('是否要退出登录?', '温馨提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning'
  })
    .then(() => {
      router.replace('/login')
      proxy._storage.SStorage.clear()
    })
    .catch(() => { })
}
const goHome = () => {
  router.replace('/index')
}


const emit = defineEmits(['color-red']);
const getAddcolor = () => {
  if(sessionStorage.getItem('color') == 'blue' ){
    emit('data-sent', 'color-white');
    zColor.value = headColor;
    sessionStorage.removeItem('color');
  }else{
    emit('data-sent', 'color-blue');
    zColor.value='white'
    console.log(zColor.value);
  }

}
</script>

<style lang="scss">

.header-box {
  width: 100%;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #00B5AD !important;
  box-sizing: border-box;
  padding: 12px 24px;
  overflow: hidden;
  border-bottom: 1px solid var(--border-color);

  .header-left {
    display: flex;
    align-items: center;
    height: 100%;
  }

  .header-right {
    display: flex;
    align-items: center;
  }

  .header-title {
    margin: 0 36px 0 12px;
    // color: var(--header-font-color);
    font-size: 22px;
    font-weight: 600;
    line-height: 32px;
  }

  .header-avatar {
    width: 32px;
    height: 32px;
    cursor: pointer;
    border-radius: 50%;
    overflow: hidden;
  }

  .header-user-name {
    // color: rgba(0, 0, 0, 0.9);
    font-size: 14px;
    line-height: 22px;
    margin-left: 12px;
  }
}
</style>
